package servlet;

import bean.Result;
import biz.ShopBiz;
import com.google.gson.Gson;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "ShopdialogServlet", value = "/ShopdialogServlet.s")
public class ShopdialogServlet extends HttpServlet {
    private ShopBiz biz = new ShopBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Result result;
        try{
            // 获取数据
            String goodsname = request.getParameter("goodsname");

            Map<String, Object> data = biz.dialogquery(goodsname);
            result = new Result(1, "成功!", data);// 返回前台
        }catch (Exception e){
            e.printStackTrace();
            System.out.println(e);
            result = new Result(0, "显示失败!", null);
        }
        String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
